#include <iostream>
#include <string>
#include <list>
#include <cstdlib>

#include "protoMsg.h"

using namespace std;

class ProtoLoaderErrorCollector :
          public google::protobuf::compiler::MultiFileErrorCollector
{
    public:
        ProtoLoaderErrorCollector() { };
        ~ProtoLoaderErrorCollector() { };
        void AddError(const string &filename,
                      int32_t line,
                      int32_t column,
                      const string &message);
};

void ProtoLoaderErrorCollector::AddError(const string &filename,
            int32_t line, int32_t column, const string &message)
{
    cerr << "Error loading proto:" << filename << endl;
    cerr << "    line:" << line << ", column:" << column << endl;
    cerr << "    msg:" << message << endl;
}

int main()
{
    ProtoLoaderErrorCollector errorCollector;
    GpbMessage msg(&errorCollector);

    string protoSrc(getenv("HOME"));
    protoSrc += "/protos";

    int rc = msg.import(protoSrc, "seaquest", "query_progress");
    cout << "rc = " << rc << endl;

    msg.import(protoSrc, "protest", "rep2");
    list <string> tokenlist;
    tokenlist.push_back("2");
    tokenlist.push_back("3");
    tokenlist.push_back("10");
    tokenlist.push_back("Name1");
    tokenlist.push_back("20");
    tokenlist.push_back("Name2");
    tokenlist.push_back("30");
    tokenlist.push_back("Name3");
    int componentId = 13;

    msg.fill(tokenlist, componentId);
    cout << '{' <<  msg.DebugString() << '}' << endl;
    return 0;
}

